import 'package:flutter/material.dart';
import 'package:flutter_base/provider_demo2/models/counter_model.dart';
import 'package:provider/provider.dart';

class SecondPage extends StatefulWidget {
  const SecondPage({super.key});

  @override
  State<SecondPage> createState() => _SecondPageState();
}

class _SecondPageState extends State<SecondPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('二级页面')),
      body: Column(
        children: [
          /*
          Consumer<CounterModel>(
            builder: (context, value, child) => Text('Counter: ${value.counter}'),
            child: ElevatedButton(
              onPressed: () {},
              child: const Text('测试子按钮'),
            ),
          ),
          Consumer<CounterModel>(
            builder: (context, value, child) => IconButton(
              onPressed: () {
                value.increment();
              },
              icon: const Icon(Icons.add),
            ),
          ),
          */
          Consumer<CounterModel>(
            builder: (context, value, child) => Column(
              children: [
                Text('Counter: ${value.counter}'),
                IconButton(
                  onPressed: () {
                    value.increment();
                  },
                  icon: const Icon(Icons.add),
                )
              ],
            ),
          ),
          TestWidget(),
        ],
      ),
    );
  }
}

class TestWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    debugPrint('构建TestWidget');

    return Container(
      decoration: const BoxDecoration(color: Colors.red),
      width: 100,
      height: 100,
    );
  }
}
